﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace QuanLyShopCD
{
    public partial class frm_QLDanhMuc : Form
    {
        public frm_QLDanhMuc()
        {
            InitializeComponent();
        }

       // BindingManagerBase db;

        private void frm_QLDanhMuc_Load(object sender, EventArgs e)
        {
            //AcessData con = new AcessData();
            //con.Open();
            //DataTable tb = con.Get_DataTable("select * from Danhmuc");
            //this.dataGridView1.DataSource = tb;
            ////con.Close();
            //db = this.BindingContext[tb];
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {

        }

        private void textBox2_TextChanged(object sender, EventArgs e)
        {

        }

        private void bt_themmoi_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    AcessData con = new AcessData();
            //    con.Open();
            //    String MaDM = txt_madm.Text;
            //    String TenDM = txt_tendm.Text;
            //    this.dataGridView1.DataSource = con.Execute_ps("ps_DanhMuc1", MaDM, TenDM);
            //    //String SQL = "insert into danhmuc(MaDm,TenDM) values('" + MaDM + "','" + TenDM + "')";
            //    //con.Execute_SQL(SQL);
            //    //DataSet ds = new DataSet();
            //    //ds = con.Get_DataSet(ref ds, "select * from danhmuc");
            //    //this.dataGridView1.DataSource = ds.Tables[0];
            //}
            //catch(Exception ex)
            //{
            //    Console.Write("loi "+ex.Message);
            //    MessageBox.Show("MaDm nay da ton tai","thong bao",MessageBoxButtons.OK,MessageBoxIcon.Question);
            //}
   
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //DialogResult result;
            //result = MessageBox.Show("ban co muon xoa hay khong!","thong bao",MessageBoxButtons.OKCancel,MessageBoxIcon.Question);
            //if (result == DialogResult.OK)
            //{
            //    AcessData ac = new AcessData();
            //    ac.Open();
            //    String madm = txt_madm.Text;
            //    String SQL = "Delete from DanhMuc where Madm = '" + madm + "'";
            //    ac.Execute_SQL(SQL);

            //    DataTable tb = ac.Get_DataTable("select * from DanhMuc");
            //    this.dataGridView1.DataSource = tb;
            //}
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //String madm = txt_madm.Text;
            //String tendm = txt_tendm.Text;
            //AcessData ac = new AcessData();
            //ac.Open();
            //String SQL = "Update DanhMuc set Madm = '" + madm + "', TenDm = '" + tendm + "'where Madm = '"+madm+"'";
            //ac.Execute_SQL(SQL);

            //DataTable tb = ac.Get_DataTable("select * from DanhMuc");
            //this.dataGridView1.DataSource = tb;

        }

        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {
            //int i = e.RowIndex;
            //AcessData con = new AcessData();
            //con.Open();
            //DataTable tb = con.Get_DataTable("select * from Danhmuc");
            //if (i < tb.Rows.Count - 1)
            //{
            //    txt_madm.Text = tb.Rows[i][0].ToString();
            //    txt_tendm.Text = tb.Rows[i][1].ToString();
            //}
            //else
            //{
            //    txt_madm.Text = "";
            //    txt_tendm.Text = "";
            //}
        }

        private void button3_Click(object sender, EventArgs e)
        {
         //   this.db.Position += 1;
        }

        private void button4_Click(object sender, EventArgs e)
        {
           // this.db.Position -= 1;
        }

        private void button5_Click(object sender, EventArgs e)
        {
            
        //    this.db.Position = dataGridView1.RowCount;
        }

        private void button6_Click(object sender, EventArgs e)
        {
          //  this.db.Position = 0;
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //AcessData con = new AcessData();
            //con.Open();
            //DataTable tb = (DataTable)dataGridView1.DataSource;
            //con.Update_Dataset(ref tb, "select * from DanhMuc");
            
        }

        private void button8_Click(object sender, EventArgs e)
        {
            
        }
    }
}
